package com.effectiv.gooruda.security.rest;

import org.springframework.security.core.context.SecurityContextHolder;

import com.effectiv.gooruda.domain.Application;

public class RESTSecurityUtil {

	public static String getAppId() {
		return getApplication().getId();
	}

	public static Application getApplication() {
		RESTUser restUser = (RESTUser) SecurityContextHolder.getContext()
				.getAuthentication().getPrincipal();

		if (restUser == null) {
			throw new IllegalAccessError(
					"API is accessed without authentication. App id missing");
		}
		
		return restUser.getApplication();
	}
}
